﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.EntityClient;

namespace Management
{
    public static class Methods
    {
        public static decimal ToCurrency(this string deger)
        {
            if (!string.IsNullOrEmpty(deger))
            {
                //NumberFormatInfo LocalFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
                //string sembol = LocalFormat.NumberDecimalSeparator;
                //if (sembol == ".")
                //{
                //  return Convert.ToDecimal(deger.Replace('.', ','));
                //}
                //else
                //{
                //  return Convert.ToDecimal(deger.Replace(',', '.'));
                //}
                return Convert.ToDecimal(deger.Replace('.', ','));
            }
            else
                return 0;
        }

        public static string ToFullSqlString(this DateTime tarih)
        {
            return string.Format("{0}-{1}-{2} {3}:{4}:{5}", tarih.Year, tarih.Month, tarih.Day, tarih.Hour, tarih.Minute, tarih.Second);
        }

        public static string ToSqlString(this DateTime tarih)
        {
            return string.Format("{0}-{1}-{2} 00:00:00", tarih.Year, tarih.Month, tarih.Day);
        }

        public static DateTime ToFullDateTime(this string tarih)
        {
            string[] date = tarih.Split(' ')[0].Split('-');
            string[] saat = tarih.Split(' ')[1].Split(':');
            return new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2]), int.Parse(saat[0]), int.Parse(saat[1]), int.Parse(saat[2]));
        }

        public static DateTime ToDateTime(this string tarih)
        {
            string[] date = tarih.Split(' ')[0].Split('-');
            return new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2]));
        }


        public static string Create()
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
            builder.DataSource = Program.Session[Settings.ServerName].ToString();
            builder.InitialCatalog = Program.Session[Settings.DatabaseName].ToString();
            builder.MultipleActiveResultSets = true;

            if (Program.Session[Settings.AuthenticateMode].ToString() == "Sql")
            {
                builder.UserID = Program.Session[Settings.UserName].ToString();
                builder.Password = Program.Session[Settings.Password].ToString();
                builder.IntegratedSecurity = false;
            }
            else
                builder.IntegratedSecurity = true;

            string providerString = builder.ToString();
            EntityConnectionStringBuilder ent = new EntityConnectionStringBuilder();
            ent.Provider = "System.Data.SqlClient";
            ent.ProviderConnectionString = providerString;
            ent.Metadata = @"res://*/Mikro.csdl|res://*/Mikro.ssdl|res://*/Mikro.msl";

            return ent.ToString();
        }

    }
}
